<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2023/10/16
  Time: 16:38
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>宠物管理</title>
</head>
<body>
<center>
    <form action="/pet/page">
        <input type="text" name="name">
        <button>查询</button>
        <a href="/pet/page"><input type="button" value="重置"></a>
        <a href="/add.jsp"><input type="button" value="添加"></a>
    </form>
    <table border="1" cellspacing="0" cellpadding="10" width="800px" style="text-align: center">
        <tr>
            <th>id</th>
            <th>宠物名称</th>
            <th>宠物类别</th>
            <th>宠物年龄</th>
            <th>宠物性别</th>
            <th>修改</th>
            <th>删除</th>
        </tr>
        <c:forEach items="${page.list}" var="pet">
            <tr>
                <td>${pet.id}</td>
                <td>${pet.name}</td>
                <td>${pet.type}</td>
                <td>${pet.age}</td>
                <td>${pet.sex}</td>

            <td><a href="/pet/updatePage?id=${pet.id}">修改</a></td>
            <td><a href="" class="delete" id="${pet.id}">删除</a></td>
        </tr>
    </c:forEach>
</table>
</center>
<script src="/static/js/jquery/jquery-3.7.1.min.js"></script>
<script>
    $(function () {
        $(".delete").click(function () {
            let id = $(this).attr("id");
            var re = confirm('确认删除吗？');
            if (re === true) {
                //执行删除
                $.post('/pet/delete', {id: id}, function (e) {
                    if (e.result) {
                        location.reload();
                        console.log(e)
                        console.log(e.message)
                    } else {
                        console.log(e)
                    }
                })
            return false;
            }
        })

    })
</script>
</body>
</html>
